<template>
	<view>
		<view style="padding-bottom: 160rpx">
			<view class="avatar">
				<view v-if="currentScene.isDefault !== 1">
					<template v-if="iconValue !== ''">
						<image :src="iconValueEncode" lazy-load :style="'border-radius:100%;background:' + colorValue" class="icon-xxl" @tap="onBindtapSetIcon"></image>
					</template>
					<template v-else>
						<image :src="defaultIcon" class="icon-xxl" style="background: #15b5b3;border-radius: 80rpx;" @tap="onBindtapSetIcon"></image>
					</template>
					<view class="avatar-txt" @tap="onBindtapSceneName(sceneName)">
						<text>{{ sceneName }}</text>
						<uni-icons custom-prefix="iconfont" type="icon-bianjibiaoge_o" size="30"></uni-icons>
					</view>
				</view>
				<view v-else>
					<template v-if="iconValue !== ''">
						<image :src="iconValueEncode" lazy-load :style="'border-radius:100%;background:' + colorValue" class="icon-xxl"></image>
					</template>
					<template v-else>
						<uni-icons custom-prefix="iconfont" type="icon-pic-default" size="88"></uni-icons>
					</template>
					<view class="avatar-txt">
						<text>{{ sceneName }}</text>
					</view>
				</view>
			</view>

			<j-cell-group>
				<j-cell title="选择条件" :more="false" @tap.native="onBindtapCondition" v-if="currentScene.isDefault !== 1">
					<view slot="tips">
						<uni-icons custom-prefix="iconfont" type="icon-zengjia1" size="30" color="#FF0025" style="margin-right:20rpx;"></uni-icons>
					</view>
				</j-cell>
				<view style="padding: 20rpx 0; border-bottom: 1px solid #eeeeee"
					v-if="(sceneType === 0 || conditionList.length > 0) && currentScene.isDefault !== 1">
					<radio-group  v-if="sceneType != 0"  style="display: flex; flex-direction: row; justify-content: space-around"
						@change="onBindchange">
						<radio value="0" :checked="conditionLogic === 0">满足任一条件</radio>
						<radio value="1" :checked="conditionLogic === 1">满足所有条件</radio>
					</radio-group>
				</view>
				<j-cell-slider v-if="sceneType === 0" icon="icon-bianji2" title="一键执行"
					sub-title="例如：一键关闭家里所有的灯" :more="false" @jfdelete="onBinddeleteOnekey"
					:is-touch="currentScene.isDefault !== 1"></j-cell-slider>
				<template v-for="(item, index) in conditionList">
					<j-cell-slider :key="index" v-if="item.conditionType === 1" icon="icon-clock"
						title="定时器" :sub-title="timer" @jftap="onBindtapSetTimer" @jfdelete="onBinddeleteTimer">
					</j-cell-slider>
				</template>
				<!-- icon="icon-PIR" -->
				<template v-for="(item, index) in conditionList">
					<j-cell-slider :key="index" v-if="item.conditionType === 0" :title="item.refDevice.deviceName" :sub-title="item.refDevice.description" :tips="item.conditionValue.propName" @jftap="onBindtapDeviceStatus(item)" @jfdelete="onBinddeleteDeviceStatus(item)">
						<view  slot="icon">
							<image class="icon" :src="item.refDevice.devicePic"></image>
						</view>
					</j-cell-slider>
				</template>
			</j-cell-group>

			<j-cell-group v-if="isShowAction">
				<j-cell title="选择动作" :more="false" @tap.native="onBindtapAction">
					<view slot="tips">
						<uni-icons custom-prefix="iconfont" type="icon-zengjia1" size="30" color="#FF0025" style="margin-right:20rpx;"></uni-icons>
					</view>
				</j-cell>
				<template v-for="(item, index) in actionList">
					<j-cell-slider :key="index" v-if="item.actionType === 0" :title="item.refDevice.deviceName" :sub-title="item.refDevice.description" :tips="item.actionValue.propName" @jftap="onBindtapActionDeviceStatus(item)" @jfdelete="onBinddeleteActionDeviceStatus(item)">
						<view slot="icon">
							<image class="icon" :src="item.refDevice.devicePic"></image>
						</view>
					</j-cell-slider>
					<j-cell-slider :key="index" icon="icon-video-camera" v-if="item.actionType === 2"
						:title="item.actionName" :sub-title="item.description" :tips="item.actionValue.propName" @jftap="onBindtapActionCopy(item)"
						@jfdelete="onBinddeleteActionCopy(item)"></j-cell-slider>
				</template>
			</j-cell-group>

			<view class="bottom-fixed">
				<button class="radius-btn" v-if="!!sceneId" type="warn" style="width: auto; margin: 0 20rpx"
					@tap="onBindtapDeleteScene">删除场景</button>
				<button class="radius-btn" v-if="!!sceneId" type="primary" style="width: auto; margin: 0 20rpx"
					@tap="onBindtapEditScene">修改智能场景</button>
				<button class="radius-btn" v-else type="primary" style="width: auto; margin: 0 20rpx"
					@tap="onBindtapCreateScene">创建智能场景</button>
			</view>
		</view>
		
		<uni-popup ref="popup" @change="change" @maskClick="maskClick" class="popupName">
			<view style="padding: 40rpx;background: #FFFFFF; border-radius: 10rpx;">
				<form class="form" @submit="submit">
					<view class="form-item">
						<input :focus="focus" placeholder="请输入家庭名称" name="sceneNameCopy" v-model="sceneNameCopy"
							class="form-control" style="background: #f6f6f6" @confirm="submit" />
					</view>
					<view class="form-item">
						<button class="block radius-btn" type="primary" form-type="submit">确认</button>
					</view>
				</form>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// 全局方法
				formatWeektoString: getApp().globalData.utils.formatWeektoString,
				parseCron: getApp().globalData.utils.parseCron,
				defaultIcon:'',
				currentScene: {
					isDefault: 0
				},
				// 当前场景
				sceneId: '',
				// 场景ID
				iconId: '',
				// 场景图标ID
				iconValue: '',
				// 场景图标地址
				iconValueEncode: '',
				// 白色图标
				colorId: '',
				// 场景图标颜色ID
				colorValue: '',
				// 场景图标颜色值
				sceneName: '我的智能场景',
				//场景名称
				sceneType: 1,
				// 场景类型
				description: '',
				// 场景描述
				conditionLogic: 0,
				// 触发逻辑:全部满足-1 任意满足-0
				isEnable: 0,
				// 场景开关:启用-1未启用-0
				isDefault: 0,
				// 是否默认:是-1否-0
				conditionList: [],
				// 场景条件列表
				actionList: [],
				// 场景任务列表
				timer: '',
				//定时器描述
				focus: false,
				// 初始input时获得焦点
				sceneNameCopy: '',
				// 表单input
				isShowAction: false, // 是否显示动作
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad: function(options) {
			console.log('=== scene:scene-create:onLoad:', options, options.sceneId);
			this.sceneId = options.sceneId
			this.initScene();
			this.getIconList()
		},
		onShow: function() {
			console.log('=== scene:scene-create:onShow:'); // 根据传参字段sceneId判断 创建场景 或 编辑场景
			if (this.sceneId) {
				console.log('编辑场景');
				uni.setStorageSync('isEditScene',true)
				this.update();
			} else {
				console.log('创建场景');
				this.create();
			}
		},
		onUnload: function() {
			console.log('--- scene:scene-create:onUnload:');
			uni.removeStorageSync('scene');
			uni.removeStorageSync('isEditScene')
		},
		methods: {
			// 查询场景图标和颜色列表
			getIconList() {
			    getApp().globalData.api.getIconList((result) => {
					console.log('场景',result);
			        let icon = result.icon[0].value;
					this.defaultIcon = `${getApp().globalData.iconUrl}?rgb=${encodeURIComponent('#FFFFFF')}&url=${icon}`
					console.log("this.defaultIcon====: ",this.defaultIcon);
					getApp().syncScene(this, {
					    iconId: result.icon[0].id,
					    iconValue: result.icon[0].value,
					    iconValueEncode: this.defaultIcon, // 白色图标
						colorId: result.color[0].id,
						colorValue: result.color[0].value
					});
					console.log('ddddddddddddddddddddd',this.currentScene.isDefault,this.iconValue,this.iconValueEncode)
			    });
			},
			// 初始化场景缓存
			initScene() {
				uni.setStorageSync('scene', {
					sceneId: '',
					// 场景ID
					iconId: '',
					// 场景图标ID
					iconValue: '',
					// 场景图标地址
					colorId: '',
					// 场景图标颜色ID
					colorValue: '',
					// 场景图标颜色值
					sceneName: '我的智能场景',
					//场景名称
					sceneType: 1,
					// 场景类型
					description: '',
					// 场景描述
					conditionLogic: 0,
					// 触发逻辑:全部满足-1 任意满足-0
					isEnable: 0,
					// 场景开关:启用-1未启用-0
					isDefault: 0,
					// 是否默认:是-1否-0
					conditionList: [],
					// 场景条件列表
					actionList: [] // 场景任务列表
				});
			},

			// 初始化（创建场景时）
			create() {
				let sceneCache = uni.getStorageSync('scene'); // getApp().globalData.scene

				this.sceneId = ''
				this.iconId = sceneCache.iconId
				this.iconValue = sceneCache.iconValue
				this.iconValueEncode = `${getApp().globalData.iconUrl}?rgb=${encodeURIComponent('#FFFFFF')}&url=${sceneCache.iconValue}`
				this.colorId = sceneCache.colorId
				this.colorValue = sceneCache.colorValue
				this.sceneName = sceneCache.sceneName
				this.sceneType = sceneCache.sceneType
				this.description = sceneCache.description
				this.conditionLogic = sceneCache.conditionLogic
				this.isEnable = sceneCache.isEnable
				this.isDefault = sceneCache.isDefault
				this.conditionList = sceneCache.conditionList
				this.actionList = sceneCache.actionList
				// 判断是否显示时间-定时器描述 timer

				console.log('场景=====',sceneCache);
				if (sceneCache.conditionList.length > 0) {
					console.log('场景=====',sceneCache.conditionList);
					let i = sceneCache.conditionList.findIndex(el => el.conditionType == 1);
					if(i != -1){
						let fields = this.parseCron(sceneCache.conditionList);
						let dayOfWeek = fields.dayOfWeek;
						let hour = fields.hour[0];
						let minute = fields.minute[0];
						this.timer = `${this.formatWeektoString(dayOfWeek)} | ${hour}:${minute <= 9 ? '0' + minute : minute}`
					}
				} // 判断是否显示动作

				if (sceneCache.sceneType === 0 || sceneCache.conditionList.length > 0) {
					this.isShowAction = true
				}
			},

			// 编辑（编辑场景时）
			update() {
				// 这里取缓存数据，为了区分已有场景首次进入编辑场景页面（走接口） 和 编辑场景过程中返回编辑场景页面（走缓存）
				if (uni.getStorageSync('scene').sceneId) {
					console.log('走缓存：');
					this.editScene();
				} else {
					console.log('走接口：');
					this.getScene();
				}
			},

			// 编辑场景
			editScene() {
				let sceneCache = uni.getStorageSync('scene'); // getApp().globalData.scene

				this.sceneId = sceneCache.sceneId
				this.iconId = sceneCache.iconId
				this.iconValue = sceneCache.iconValue
				this.iconValueEncode = `${getApp().globalData.iconUrl}?rgb=${encodeURIComponent('#FFFFFF')}&url=${sceneCache.iconValue}`
				this.colorId = sceneCache.colorId
				this.colorValue = sceneCache.colorValue
				this.sceneName = sceneCache.sceneName
				this.sceneType = sceneCache.sceneType
				this.description = sceneCache.description
				this.conditionLogic = sceneCache.conditionLogic
				this.isEnable = sceneCache.isEnable
				this.isDefault = sceneCache.isDefault
				this.conditionList = sceneCache.conditionList
				this.actionList = sceneCache.actionList
				// 判断是否显示时间-定时器描述 timer
				if (sceneCache.conditionList.length > 0) {
					let fields = this.parseCron(sceneCache.conditionList);
					let dayOfWeek = fields.dayOfWeek;
					let hour = fields.hour[0];
					let minute = fields.minute[0];
					this.timer = `${this.formatWeektoString(dayOfWeek)} | ${hour}:${minute <= 9 ? '0' + minute : minute}`
				} // 判断是否显示动作

				if (sceneCache.sceneType === 0 || sceneCache.conditionList.length > 0) {
					this.isShowAction = true
				}
			},

			// 查询单个场景
			getScene() {
				getApp().globalData.api.getScene({
					sceneId: this.sceneId
				}, (result) => {
					console.log('查询单个场景:', result, getApp());
					getApp().syncScene(this, {
						currentScene: result,
						sceneId: result.sceneId,
						iconId: result.iconId,
						iconValue: result.iconValue,
						iconValueEncode: `${getApp().globalData.iconUrl}?rgb=${encodeURIComponent('#FFFFFF')}&url=${result.iconValue}`,
						colorId: result.colorId,
						colorValue: result.colorValue,
						sceneName: result.sceneName,
						sceneType: result.sceneType,
						description: result.description,
						conditionLogic: result.conditionLogic,
						isEnable: result.isEnable,
						isDefault: result.isDefault,
						conditionList: result.conditionList,
						actionList: result.actionList
					}); // 判断是否显示时间-定时器描述 timer

					if (result.conditionList.length > 0) {
						// 定时器描述 timer
						let fields = this.parseCron(result.conditionList);
						let hour = fields.hour[0];
						let minute = fields.minute[0];
						let dayOfWeek = fields.dayOfWeek;
						this.timer =
							`${this.formatWeektoString(dayOfWeek)} | ${hour} : ${minute <= 9 ? '0 ' + minute : minute}`
					} // 判断是否显示动作

					if (result.sceneType === 0 || result.conditionList.length > 0) {
						this.isShowAction = true
					}
				});
			},

			// 设备列表
			getDeviceListByPage(callback) {
				const data = {
					userGroupId: uni.getStorageSync('currentGroupId'),
					// getApp().globalData.currentGroupId,
					isAdmin: true,
					page: 1,
					limit: 999
				};
				getApp().globalData.api.getDeviceListByPage(data, (result) => {
					callback(result.data);
				});
			},

			// 设置场景图标和颜色
			onBindtapSetIcon(ev) {
				uni.navigateTo({
					url: '/jvss/pagesScene/scene-create-seticon/scene-create-seticon'
				});
			},

			// 设置场景名称
			onBindtapSceneName(ev) {
				this.$refs.popup.open()
				this.sceneNameCopy = ev
				setTimeout(() => {
					this.focus = true
				}, 350);
			},

			// 表单提交
			submit(ev) {
				if (this.sceneNameCopy.replace(/\s/g, '') === '') {
					uni.showToast({
						title: '请输入场景名称',
                        icon: 'none'
					});
					return;
				}
				getApp().syncScene(this, {
					focus: false,
					sceneName: this.sceneNameCopy
				});
				this.$refs.popup.close()
			},

			change(ev) {
				console.log('change:', ev);
			},

			maskClick(ev) {
				console.log('maskClick:', ev);
				this.focus = false
				this.$refs.popup.close()
			},

			// 选择条件
			onBindtapCondition(ev) {
				if(this.sceneType == 0){
					uni.showToast({
						title:'一键执行场景下无法添加其他条件',
						icon:'none'
					})
					return
				}
				uni.navigateTo({
					url: '/jvss/pagesScene/condition/condition'
				});
			},

			// 单选条件
			onBindchange(ev) {
				// this.conditionLogic = getApp().globalData.scene.conditionLogic = Number(ev.detail.value)
				// this.conditionLogic = Number(ev.detail.value)
				// let scene = wx.getStorageSync('scene')
				// scene.conditionLogic = Number(ev.detail.value)
				// wx.setStorageSync('scene', scene)
				getApp().syncScene(this, {
					conditionLogic: Number(ev.detail.value)
				});
			},

			// 设置定时器
			onBindtapSetTimer() {
				uni.navigateTo({
					url: '/jvss/pagesScene/condition-timer/condition-timer'
				});
			},

			// 点击智能设备状态变化
			onBindtapDeviceStatus(ev) {
				console.log('智能设备条件:', ev);
				let condition = ev
				uni.navigateTo({
					url: `/jvss/pagesScene/condition-status-prop-control/condition-status-prop-control?condition=${encodeURIComponent(JSON.stringify(condition))}`
				});
			},

			// 点击已创建的智能任务
			onBindtapActionDeviceStatus(ev) {
				console.log('智能设备任务:', ev);
				let action = ev;
				uni.navigateTo({
					url: `/jvss/pagesScene/action-status-prop-control/action-status-prop-control?action=${encodeURIComponent(JSON.stringify(action))}`
				});
			},

			// 点击复制已有场景任务
			onBindtapActionCopy(ev) {
				// TODO（应该不能点，如果可以点击，则是跳转到不可操作的查看页）
				// console.log(ev);
				// let action = ev
				uni.navigateTo({
					url: '/jvss/pagesScene/action-copy/action-copy?enter=true'
				});
			},

			// 选择动作任务
			onBindtapAction(ev) {
				uni.navigateTo({
					url: '/jvss/pagesScene/action/action'
				});
			},

			// 确认并创建智能场景
			onBindtapCreateScene() {
				let sceneCache = uni.getStorageSync('scene'); // getApp().globalData.scene

				const iconId = sceneCache.iconId;
				const iconValue = sceneCache.iconValue;
				const colorId = sceneCache.colorId;
				const colorValue = sceneCache.colorValue;
				const sceneName = sceneCache.sceneName;
				const sceneType = sceneCache.sceneType;
				const description = sceneCache.description;
				const conditionLogic = sceneCache.conditionLogic;
				const isEnable = sceneCache.isEnable;
				const isDefault = sceneCache.isDefault;
				const conditionList = sceneCache.conditionList;
				const actionList = sceneCache.actionList;
				console.log('传参：：：', sceneCache);

				if (!iconId) {
					uni.showToast({
						title: '场景图标不能为空',
						icon:'none'
					});
					return;
				}

				if (!colorId) {
					uni.showToast({
						title: '场景图标背景颜色不能为空',
						icon:'none'
					});
					return;
				}

				if (!sceneName) {
					uni.showToast({
						title: '场景名称不能为空',
						icon:'none'
					});
					return;
				}

				if (sceneType === 1 && !conditionList.length) {
					uni.showToast({
						title: '场景条件不能为空',
						icon:'none'
					});
					return;
				}

				if (!actionList.length) {
					uni.showToast({
						title: '场景动作不能为空',
						icon:'none'
					});
					return;
				}

				for (let i = 0; i < conditionList.length; i++) {
					const item = conditionList[i];
					delete item.refDevice; // item.conditionValue = JSON.stringify(item.conditionValue)
				}

				for (let i = 0; i < actionList.length; i++) {
					const item = actionList[i];
					delete item.refDevice;
					delete item.refScene; // item.actionValue = JSON.stringify(item.actionValue)
				}

				const data = {
					iconId,
					colorId,
					sceneName,
					sceneType,
					groupId: uni.getStorageSync('currentGroupId'),
					// getApp().globalData.currentGroupId,
					description,
					conditionLogic,
					isEnable,
					isDefault,
					conditionList,
					actionList
				};
				console.log('传参2：', data);
				getApp().globalData.api.createScene(data, (result) => {
					uni.showToast({
						title: '创建场景成功！',

						success(res) {
							uni.switchTab({
								url: '/jvss/pages/scene/home'
							});
						}
					});
				});
			},

			// 确认并修改智能场景
			onBindtapEditScene() {
				let sceneCache = uni.getStorageSync('scene'); // getApp().globalData.scene

				const sceneId = sceneCache.sceneId;
				const iconId = sceneCache.iconId;
				const iconValue = sceneCache.iconValue;
				const colorId = sceneCache.colorId;
				const colorValue = sceneCache.colorValue;
				const sceneName = sceneCache.sceneName;
				const sceneType = sceneCache.sceneType;
				const description = sceneCache.description;
				const conditionLogic = sceneCache.conditionLogic;
				const isEnable = sceneCache.isEnable;
				const isDefault = sceneCache.isDefault;
				const conditionList = sceneCache.conditionList;
				const actionList = sceneCache.actionList;
				console.log('传参：：：', sceneCache);

				if (!iconId) {
					uni.showToast({
						title: '场景图标不能为空'
					});
					return;
				}

				if (!colorId) {
					uni.showToast({
						title: '场景图标背景颜色不能为空'
					});
					return;
				}

				if (!sceneName) {
					uni.showToast({
						title: '场景名称不能为空'
					});
					return;
				}

				if (sceneType === 1 && !conditionList.length) {
					uni.showToast({
						title: '场景条件不能为空'
					});
					return;
				}

				if (!actionList.length) {
					uni.showToast({
						title: '场景动作不能为空'
					});
					return;
				}

				for (let i = 0; i < conditionList.length; i++) {
					const item = conditionList[i];
					delete item.refDevice; // item.conditionValue = JSON.stringify(item.conditionValue)
				}

				for (let i = 0; i < actionList.length; i++) {
					const item = actionList[i];
					delete item.refDevice;
					delete item.refScene; // item.actionValue = JSON.stringify(item.actionValue)
				}

				const data = {
					sceneId,
					iconId,
					colorId,
					sceneName,
					sceneType,
					groupId: uni.getStorageSync('currentGroupId'),
					// getApp().globalData.currentGroupId,
					description,
					conditionLogic,
					isEnable,
					isDefault,
					conditionList,
					actionList
				};
				console.log('传参2：', data);
				getApp().globalData.api.updateScene(data, (result) => {
					uni.showToast({
						title: '修改场景成功！',
						duration:1000,
						icon:'none',
						success(res) {
							setTimeout(()=>{
								uni.switchTab({
									url: '/jvss/pages/scene/home'
								});
							},1000)
							
						}
					});
				});
			},

			// 删除一键执行
			onBinddeleteOnekey(ev) {
				// this.sceneType = getApp().globalData.scene.sceneType = 1
				// this.isShowAction = false
				// this.actionList = getApp().globalData.scene.actionList = []

				// this.sceneType =  1
				// this.actionList = []
				// this.isShowAction = false

				// let scene = wx.getStorageSync('scene')
				// scene.sceneType = 1
				// scene.actionList = []
				// wx.setStorageSync('scene', scene)
				getApp().syncScene(this, {
					sceneType: 1,
					actionList: [],
					isShowAction: false
				});
			},

			// 删除定时器
			onBinddeleteTimer(ev) {
				let arr = [];

				for (let i = 0; i < this.conditionList.length; i++) {
					const item = this.conditionList[i];

					if (item.conditionType !== 1) {
						arr.push(item);
					}
				}
				// this.conditionList = getApp().globalData.scene.conditionList = arr
				// this.conditionList = arr
				// let scene = wx.getStorageSync('scene')
				// scene.conditionList = arr

				getApp().syncScene(this, {
					conditionList: arr
				});

				if (this.conditionList.length <= 0) {
					// this.isShowAction =false
					// this.actionList =getApp().globalData.scene.actionList = []
					// this.actionList = []
					// scene.actionList = []
					getApp().syncScene(this, {
						isShowAction: false,
						actionList: []
					});
				} // wx.setStorageSync('scene', scene)
			},

			// 删除设备条件
			onBinddeleteDeviceStatus(ev) {
				console.log(ev);
				let deviceId = ev.conditionRefId;
				// const data = {
				// 	conditionId: conditionId
				// };
				// getApp().globalData.api.getSceneCondition(data, (result) => {});
				let id = ev.conditionValue.id;
				let arr = [];

				for (let i = 0; i < this.conditionList.length; i++) {
					const item = this.conditionList[i];

					if (!(item.conditionRefId === deviceId && item.conditionValue.id === id)) {
						arr.push(item);
					}
				}
				// this.conditionList = getApp().globalData.scene.conditionList = arr
				// this.conditionList = arr
				// let scene = wx.getStorageSync('scene')
				// scene.conditionList = arr

				getApp().syncScene(this, {
					conditionList: arr
				});

				if (this.conditionList.length <= 0) {
					// this.isShowAction = false
					// this.actionList = getApp().globalData.scene.actionList = []
					// this.actionList = []
					// scene.actionList = []
					getApp().syncScene(this, {
						isShowAction: false,
						actionList: []
					});
				} // wx.setStorageSync('scene', scene)
			},

			// 删除设备动作
			onBinddeleteActionDeviceStatus(ev) {
				let deviceId = ev.actionRefId;
				let id = ev.actionValue.id;
				let arr = [];

				for (let i = 0; i < this.actionList.length; i++) {
					const item = this.actionList[i];

					if (!(item.actionRefId === deviceId && item.actionValue.id === id)) {
						arr.push(item);
					}
				}
				// this.actionList = getApp().globalData.scene.actionList = arr
				// this.actionList = arr
				// let scene = wx.getStorageSync('scene')
				// scene.actionList = arr
				// wx.setStorageSync('scene', scene)

				getApp().syncScene(this, {
					actionList: arr
				});
			},

			// 删除复制场景
			onBinddeleteActionCopy(ev) {
				let actionId = ev.actionRefId;
				let arr = [];

				for (let i = 0; i < this.actionList.length; i++) {
					const item = this.actionList[i];

					if (item.actionRefId !== actionId) {
						arr.push(item);
					}
				}
				// this.actionList = getApp().globalData.scene.actionList = arr
				// this.actionList = arr
				// let scene = wx.getStorageSync('scene')
				// scene.actionList = arr
				// wx.setStorageSync('scene', scene)

				getApp().syncScene(this, {
					actionList: arr
				});
			},

			// 删除当前场景
			onBindtapDeleteScene() {
				uni.showModal({
					title: '提示',
					content: '确认删除场景？',
					success: (res) => {
						console.log(res);

						if (res.confirm) {
							const data = {
								sceneId: this.sceneId
							};
							getApp().globalData.api.deleteScene(data, (result) => {
								console.log(result);
								uni.navigateBack({
									delta: 1
								});
							});
						}
					}
				});
			}
		}
	};
</script>
<style lang="scss">

.popupName {
    /deep/ .uni-popup__wrapper {
        top: -100rpx;
    }
}
	.avatar {
		display: flex;
		justify-content: center;
		padding: 80rpx 0;
		text-align: center;
	}

	.avatar-txt {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.icon{
		width: 40rpx;
		height: 40rpx;
		margin-left: 20rpx;
	}
</style>
